<%--
  Created by IntelliJ IDEA.
  User: Allen
  Date: 2017/5/17
  Time: 22:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css"></style>
    <script src="../../resource/js/jquery-3.2.1.js"></script>
</head>


<body>


<input type="button" value="发送json数据(本地)" onclick="signInData('http://localhost:8080/0/sign_intest')" /><br/>
<input type="button" value="发送json数据(远端)" onclick="signInData('http://10.92.61.37:8080/0/sign_intest')" /><br/><br/>

phone: <input type="text" id="phone"/><br/>
passd: <input type="text" id="password"/><br/><br/>

<input type="button" value="注册(本地)" onclick="signUpData('http://localhost:8080/0/sign_up')" /><br/>
<input type="button" value="注册(远端)" onclick="signUpData('http://10.92.61.37:8080/0/sign_up')" /><br/>

<hr/>

<form action="/0/sign_in_t2" method="post">
    phone: <input type="text" name="phoneNumber"/><br/>
    passd: <input type="text" name="password"/><br/>
    <input type="submit" value="登陆"/>
</form>
<hr/>
<form action="/0/sign_up_t2" method="post">
    phone: <input type="text" name="phoneNumber"/><br/>
    passd: <input type="text" name="password"/><br/>
    <input type="submit" value="注册"/>
</form>


<hr/>
<form action="/0/upload_img" method="post" enctype="multipart/form-data" id="uploadForm">
    icon:   <input type="file" name="icon"/><br/>
    phone: <input type="text" name="phoneNumber"/><br/>
    nickname: <input type="text" name="nickname"/><br/>
    <input type="submit" value="Submit" onclick="uploadImg('http://localhost:8080/0/upload_img');"/>
</form>






<script type="text/javascript">


    function uploadImg(urltmp) {

        var formData = new FormData(document.querySelector("uploadForm"));
//        formData.append("CustomFiled","This is some extera data");
        $.ajax(
            {
                type:"POST",
                url: urltmp,
                contentType:"application/json;charset=UTF-8",
                dataType:"text",
                data: formData,
                success:function (returndata) {
                    alert(returndata);
                    console.log(returndata);
                },
                error:function (def) {
                    alert("上传出错"+def.status);
                    console.log("上传出错"+def);
                }
            });
        alert("上传成功");
    }


    function signInData(urltmp) {
        $.ajax({
            type: "POST",
            url: urltmp,
            dataType: "json",
            contentType:"application/json;charset=UTF-8",
            data:
                JSON.stringify({
                    phoneNumber:$('#phone').val(),
                    password:$('#password').val()
                }),
            success: function (result) {
                alert(JSON.stringify(result));
                console.log(result);
            },
            error: function (def) {
                alert("json数据出错：" + def.status);
            }
        });
    }

    function signUpData(urltmp) {
        $.ajax({
            type: "POST",
            url: urltmp,
            dataType: "json",
            contentType:"application/json;charset=UTF-8",
            data:
                JSON.stringify({
                    phoneNumber:$('#phone').val(),
                    password:$('#password').val()
                }),
            success: function (result) {
                alert(JSON.stringify(result));
                console.log(result);
            },
            error: function (def) {
                alert("json数据出错：" + def.status);
            }
        });
    }
</script>




</body>
</html>
